package weiyao.xinxidasai.mapper;

import org.apache.ibatis.annotations.*;
import weiyao.xinxidasai.DTO.ChunkPO;

import java.util.List;
@Mapper
public interface ChunkMapper {

    @Insert("INSERT INTO chunk(c_md5, c_index) VALUES(#{md5}, #{index})")
    @Options(useGeneratedKeys = true, keyProperty = "chunkId", keyColumn = "c_id")
    Integer insertChunk(ChunkPO chunkPO);

    @Delete("DELETE FROM chunk WHERE c_md5 = #{md5}")
    void deleteChunkByMd5(String md5);

    @Select("SELECT c_id AS chunkId, c_md5 AS md5, c_index AS `index` FROM chunk WHERE c_md5 = #{md5}")
    @Results({
            @Result(property = "chunkId", column = "c_id"),
            @Result(property = "md5", column = "c_md5"),
            @Result(property = "index", column = "c_index")
    })
    List<ChunkPO> selectChunkListByMd5(String md5);
}
